/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Enea.project.dcc;

import Enea.project.*;
import Enea.server.*;
import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedList;

/**
 *
 * @author davide
 */
public class DESForce implements DCC {
    final static int projectid = 1;
    EneaServer server;
    LinkedList<ClientData> clients;
    HashSet<WorkUnit> freewu;
    HashSet<WorkUnit> assignedwu;
    HashSet<ResultsPack> results;
    GlobalStats stats;

    public DESForce() {
        server = null;
        clients = new LinkedList<ClientData>();
        freewu = new HashSet<WorkUnit>();
        assignedwu = new HashSet<WorkUnit>();
        results = new HashSet<ResultsPack>();
        stats = null;
    }

    @Override
    public int getID() {
        return projectid;
    }

    @Override
    public ClientData getClientByID(int clientid) {
        for(ClientData c:clients) if (c.getClientid() == clientid) return c;
        return null;
    }

    @Override
    public void startServer(int portnumber) throws IOException {
        server = new EneaServer(portnumber, this);
        server.start();
    }

    @Override
    public WorkUnit giveMeWork(ClientData client) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void takeResults(ClientData client, ResultsPack result) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void registerNewClient(ClientData client) {
        clients.add(client);
    }

    @Override
    public GlobalStats giveMeStats() {
        //TODO: chiamata a metodo che genera statistiche.
        return stats;
    }

    @Override
    public void saveClientStats(ClientStats stats) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
